package com.itboye.zhujia.presenter;

import java.util.List;
import java.util.Observer;

import com.itboye.zhujia.base.BasePresenter;
import com.itboye.zhujia.base.ICompleteListener;
import com.itboye.zhujia.bean.PersonDataBean;
import com.itboye.zhujia.bean.ResultEntity;
import com.itboye.zhujia.interfaces.IUserInterface;
import com.itboye.zhujia.responsitory.UserRepository;

/***
 * 
 * @author 递增给Responsitory
 * 
 */
public class UserPresenter extends BasePresenter implements
		IUserInterface<PersonDataBean> {

	public UserPresenter(Observer observer) {
		super(observer);
	}

	// 用户登录
	public static final String user_success = UserPresenter.class.getName()
			+ "_User_success";// 由此判断请求的接口
	public static final String user_fail = UserPresenter.class.getName()
			+ "_User_fail";
	
	// 发送验证码
	public static final String send_success = UserPresenter.class.getName()
				+ "_Send_success";// 由此判断请求的接口
	public static final String send_fail = UserPresenter.class.getName()
				+ "_Send_fail";
		
	// 验证验证码
	public static final String verification_success = UserPresenter.class.getName()
				+ "_Verification_success";// 由此判断请求的接口
	public static final String verification_fail = UserPresenter.class.getName()
				+ "_Verification_fail";
	// 注册
	public static final String register_success = UserPresenter.class.getName()
					+ "_Rregister_success";// 由此判断请求的接口
	public static final String register_fail = UserPresenter.class.getName()
					+ "_Register_fail";
	
	// 手机找回密码
	public static final String backPass_success = UserPresenter.class.getName()
						+ "_BackPass_success";// 由此判断请求的接口
	public static final String backPass_fail = UserPresenter.class.getName()
						+ "_BackPass_fail";
	// 修改性别
	public static final String updateSex_success = UserPresenter.class.getName()
							+ "_UpdateSex_success";// 由此判断请求的接口
	public static final String updateSex_fail = UserPresenter.class.getName()
							+ "_UpdateSex_fail";
	// 修改昵称
	public static final String updateNickname_success = UserPresenter.class.getName()
								+ "_UpdateNickname_success";// 由此判断请求的接口
	public static final String updateNickname_fail = UserPresenter.class.getName()
								+ "_UpdateNickname_fail";
	// 修改昵称
	public static final String updateHead_success = UserPresenter.class.getName()
									+ "_UpdateHead_success";// 由此判断请求的接口
	public static final String updateHead_fail = UserPresenter.class.getName()
									+ "_UpdateHead_fail";
	@Override
	public void login(String userName, String pwd) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(user_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(user_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.login(userName, pwd);
	}

	/**
	 * 发送短信
	 */
	@Override
	public void send(String phone, String code) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {
					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(send_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(send_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.send(phone, code);
	}
	/**
	 * 验证验证码
	 */
	@Override
	public void verification(String mobile, String code_type, String code) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {
					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(verification_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(verification_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.verification(mobile, code_type, code);
		
	}
	/**
	 * 注册
	 */
	@Override
	public void register(String reg_type, String from, String code,
			String username, String password) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(register_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(register_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.register(reg_type, from, code, username, password);
		
	}
	/**
	 * 手机找回密码
	 */
	@Override
	public void backPass(String mobile, String code, String psw) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(backPass_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(backPass_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.backPass(mobile, code, psw);
		
	}
	/**
	 * 修改性别
	 */
	@Override
	public void updateSex(String uid, String sex) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateSex_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateSex_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateSex(uid, sex);
		
	}
	/**
	 * 修改昵称
	 */
	@Override
	public void updateNickname(String uid, String nickname) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateNickname_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateNickname_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateNickname(uid, nickname);
		
	}
	/**
	 * 修改头像
	 */
	@Override
	public void updateHead(String uid, String type,String image) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateHead_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateHead_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateHead(uid, type,image);
		
	}

}
